package cn.net.xyan.facerecognition

import cn.net.xyan.facerecognition.service.FaceService
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

import java.awt.image.BufferedImage
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import javax.imageio.ImageIO


@RunWith(SpringRunner::class)
@SpringBootTest
class FaceRecognitionApplicationTests {

	@Autowired
	lateinit var faceService:FaceService

	@Test
	fun contextLoads() {

		faceService.registerUser("abc","abc")

		val image = BufferedImage(256,256,BufferedImage.TYPE_INT_ARGB)

		val output = ByteArrayOutputStream()

		ImageIO.write(image,"png",output)

		val input = ByteArrayInputStream(output.toByteArray())

		faceService.addUserFace("abc",input)

		input.reset()

		val result = faceService.predict(input)

		println("username:${result!!.username} ")


	}

}
